import { Args, Query, Resolver, ResolveField, Parent } from '@nestjs/graphql';
import { UsersService } from './users.service';
import { UseGuards } from '@nestjs/common';
import { CurrentUser } from '../common/decorator/current-user.decorator';
import { User } from '../models/user.model';
import { Roles } from '../common/decorator/roles.decorator';
import { GqlRolesGuard } from '../auth/guards/gql-roles.guard';

@Resolver(of => User)
@UseGuards(GqlRolesGuard)
export class UsersResolver {
    constructor(
        private usersService: UsersService,
    ) { }

    @Query(returns => User)
    @Roles('member')
    async whoAmI(@CurrentUser() user: User) {
        return await this.usersService.findById(user.userId);
    }
}
